<?

include_once "accesscontrol.php";
include_once "index.php";

?>
<style type="text/css" >
table.data {
  background-color:#fff;
   color:#213243;
}
.data th {background-color:gray; color:#ffffff}
.pagingDiv {width:800px; height:20px}
.pNo {float:left; width:10px; margin-left:3px; margin-right:3px; border:0px solid gray;}
.pNo a {text-decoration:none;}
</style>

<table align=center width=400 class=BlackText>
<tr>
	<td colspan=2 align=center class=HeaderClass><font size=3><b>Success Stories </b></font><br><br></td>
</tr>
</table>

<?
//-------------------------------PAGING--------------------------------------------

// Number of records to show per page
$recordsPerPage = 10;  # 0

// default startup page
$pageNum = 1;

if(isset($_GET['p'])) {
  $pageNum = $_GET['p'];
  settype($pageNum, 'integer');
}

$offset = ($pageNum - 1) * $recordsPerPage;
//-------------------------------PAGING--------------------------------------------------

$q1 = "select * from job_story order by story_id LIMIT $offset, $recordsPerPage";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) > '0')
{
echo "<table align=center width=400><tr><td>";
while($a1 = mysql_fetch_array($r1))
{
echo "	

<table align=center width=400 border=1 cellspacing=0 cellpadding=3 bordercolor=black class=BlackText style=margin-bottom:10px>
	<tr bgcolor=#736F6E>
	<td><font color=#fffff style=\"font-size:13px; font-weight:bold\">Story $a1[story_id] </font></td>
	</tr>
	
	<tr>
	<td colspan=3>
	$a1[story]<br><br>
	 <a class=TNA href=EditStory.php?story_id=$a1[story_id]>Edit </a> | 
	 <a class=TNA href=DeleteStory.php?story_id=$a1[story_id]> Delete </a> 
	</td>
	</tr>
	</table>
	";
}
//-----------------------------------------PAGING-------------------------------------------
		
	# Update this query with same where clause you are using above.
  $query   = "SELECT COUNT(story_id) AS dt FROM job_story"; # 3

  $result  = mysql_query($query) or die('Mysql Err. 2');
  $row     = mysql_fetch_assoc($result);
  $numrows = $row['dt'];  # 4

  $maxPage = ceil($numrows/$recordsPerPage);

  $nav = '';
  for($page = 1; $page <= $maxPage; $page++)
  {
       if ($page == $pageNum)
       {
            $nav .= "<div class=\"pNo\">$page</div>";
       }
      else
       {
            $nav .= "<div class=\"pNo\"><a href=\"?p=$page\">$page</a></div>";
       }
  }

  if ($pageNum > 1)  {

       $page = $pageNum - 1;
       $prev = "<a href=\"?p=$page\"><strong>Prev</strong></a>";

       $first = "<a href=\"?p=1\"><strong>First</strong></a>";
  }
  else {
       $prev  = '<strong>  </strong>';
       $first = '<strong>   </strong>';
  }

  if ($pageNum < $maxPage) {
       $page = $pageNum + 1;
       $next = "<a href=\"?p=$page\"><strong>Next</strong></a>";

       $last = "<a href=\"?p=$maxPage\"><strong>Last</strong></a>";
  }
  else {
       $next = '<strong>  </strong>';
       $last = '<strong>   </strong>';
  }
  
  echo "<table border=0 align=right  cellspacing=0 cellpadding=0 style=\"margin-right: 20px\">
  				<tr>
  				<td>$first</td>
  				<td>$prev</td>
  				<td>$nav</td>
  				<td>$next</td>
  				<td>$last</td>
  			</table>";
//---------------------------------------PAGING----------------------------------------
	

}
else
{
	echo "<br><br><br><center><span class=TNA>There are no approved success stories, yet.</span></center><br><br>";
}

$q2 = "select * from job_story_waiting order by WS_id";
$r2 = mysql_query($q2) or die(mysql_error());

if(mysql_num_rows($r2) > '0')
{
echo "<br><br><table align=center width=400><caption align=center><b> Stories, waiting for approval.</b></caption><tr><td>";
while($a2 = mysql_fetch_array($r2))
{
echo "	
<table align=center width=400 border=1 cellspacing=0 cellpadding=3 bordercolor=black class=BlackText style=margin-bottom:10px>
	<tr bgcolor=#736F6E>
	<td><font color=#fffff style=\"font-size:13px; font-weight:bold\">Waiting Story $a2[WS_id] </font></td>
	</tr>
	
	<tr>
	<td colspan=4>
	$a2[story] 
	<br>
	<br>
	<a class=TNA href=EditWStory.php?story_id=$a2[WS_id]>Edit</a>  |  
	<a class=TNA href=DeleteWStory.php?story_id=$a2[WS_id]>Delete</a>  |  
	<a class=TNA href=ApprovalWStory.php?story_id=$a2[WS_id]>Approve</a> 
	</td>
	</tr>
	</table>
	";
}

echo "</td></tr></table>";
}
else
{
	echo "<br><br><br><center><span class=TNA>There are not success stories waiting to be approved.</span></center>";
}
echo "</td></tr></table><br>";
?>
<? include_once('../footer.php'); ?>